package chap6.task4;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Copy4Methods {
    public static void main(String[] args) throws Exception {
        long start=System.currentTimeMillis();
//        method1("D:\\copy.mp4","copy.mp4");
//        method2("D:\\copy.mp4","copy.mp4");
//        method3("D:\\copy.mp4","copy.mp4");
        method4("D:\\copy.mp4","copy.mp4");
        long end=System.currentTimeMillis();
        System.out.println("共耗时："+(end-start)+"毫秒");
    }

    private static void method3(String s, String s1) throws Exception {
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(s));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(s1));
        int by=0;
        while((by=bis.read())!=-1){
            bos.write(by);
        }
        bis.close();
        bos.close();
    }


    private static void method1(String s, String s1) throws Exception {
        FileInputStream fis=new FileInputStream(s);
        FileOutputStream fos =new FileOutputStream(s1);
        int by=0;
        while((by=fis.read())!=-1){
            fos.write(by);
        }
        fis.close();
        fos.close();
    }

    private static void method2(String s, String s1) throws Exception{
        FileInputStream fis=new FileInputStream(s);
        FileOutputStream fos =new FileOutputStream(s1);
        byte [] b=new byte[1024];
        int len=0;
        while((len=fis.read(b))!=-1){
            fos.write(b,0,len);
        }
        fos.close();
        fis.close();
    }


    private static void method4(String s, String s1) throws Exception {
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream(s));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(s1));
        byte[] b=new byte[1024];
        int len=0;
        while((len=bis.read(b))!=-1){
            bos.write(b,0,len);
        }
        bis.close();
        bos.close();
    }

}
